<?php

namespace app\erp\model;

use think\Model;

class UInvoicedb extends Model
{
    protected $connection = 'database.utec_db';
    protected $name = 'invoice';
    protected $pk = 'invoice_id';

    public function saveInvoice($order_no)
    {
        $invoicedb = new Invoicedb();
        $get_invoice = $invoicedb->where('order_nos', $order_no)->find();
        if ($get_invoice) {
            $get_invoice = $get_invoice->hidden(['invoice_id'])->toArray();
            $get_u_invoice = $this->where('order_nos', $order_no)->find();
            $get_invoice['create_time'] = strtotime($get_invoice['create_time']);
            $get_invoice['invoice_time'] = $get_invoice['invoice_time'] ? strtotime($get_invoice['invoice_time']) : null;
            if ($get_u_invoice) {
                $get_u_invoice->save($get_invoice);
            } else {
                $this->save($get_invoice);
            }


        }
    }
}